﻿using System;
using System.Linq;
using Enferno.Public.InversionOfControl;
using Enferno.Public.Web.Repositories;
using Enferno.StormApiClient.Products;
using Microsoft.Practices.Unity;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Rhino.Mocks;

namespace Enferno.Public.Web.Test
{
    [TestClass]
    public class ApplicationDictionaryTests
    {
        protected static readonly string cultureCode = "sv-SE";

        [TestMethod]
        public void ListPricelistsTest()
        {
            // Arrange
            var productsRepository = MockRepository.GenerateMock<IProductRepository>();
            productsRepository.Stub(x => x.ListPricelists()).IgnoreArguments()
                .Return(
                new PricelistList
                {
                    new Pricelist {Id = 1},
                    new Pricelist {Id = 2},
                    new Pricelist {Id = 3},
                }
            );

            var repository = MockRepository.GenerateMock<IRepository>();
            repository.Stub(x => x.Products).Return(productsRepository);

            IoC.Container.RegisterInstance(typeof(IRepository), repository, new PerThreadLifetimeManager());
            ApplicationDictionary.Instance.Refresh();
            
            // Act
            var pricelists = ApplicationDictionary.Instance.Pricelists(cultureCode);

            // Assert
            Assert.AreEqual(3, pricelists.Count());
        }
    }
}
